package com.ttai.ui.adapter;

import android.content.Context;
import android.content.Intent;
import android.content.res.Resources;
import android.database.sqlite.SQLiteDatabase;
import android.support.v7.view.menu.MenuView;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.squareup.picasso.Picasso;
import com.ttai.R;
import com.ttai.model.dao.DBHelper;
import com.ttai.model.dao.bean.Id_Item;
import com.ttai.ui.activity.IdItem;
import com.ttai.ui.activity.LoginId;

import java.util.ArrayList;

import butterknife.Bind;
import butterknife.ButterKnife;

public class LoginIdRecycleViewAdapter extends RecyclerView.Adapter {
    Context context;
//    LoginId loginId;
    private ArrayList<Id_Item> idList = new ArrayList<>();
    private Id_Item id_item;
    private String imgurl;

    public LoginIdRecycleViewAdapter(Context context) {
        this.context = context;
//        this.loginId = loginId;
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = View.inflate(context, R.layout.item_id, null);
        ViewHolder viewHoldler = new ViewHolder(view);
        return viewHoldler;
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        id_item = idList.get(position);
//        ((ViewHolder)holder).ivIditemicon.setImageDrawable(idList.get(position).getImage());
        imgurl = idList.get(position).getImage();
        ((ViewHolder)holder).tvItemname.setText(idList.get(position).getId_name());
        ((ViewHolder)holder).tvItemacountnumber.setText(idList.get(position).getId_acountnumber());
        Picasso.with(context).load(imgurl).placeholder(R.drawable.xike1).resize(150,150).into(((ViewHolder)holder).ivIditemicon);
    }

    @Override
    public int getItemCount() {
        if (idList != null && idList.size()>0){
            return idList.size();
        }
        return 0;
    }

    public void setData(ArrayList<Id_Item> idList) {
        this.idList = idList;
        notifyDataSetChanged();
    }

    public class ViewHolder extends RecyclerView.ViewHolder{
        @Bind(R.id.iv_iditemicon)
        ImageView ivIditemicon;
        @Bind(R.id.tv_itemname)
        TextView tvItemname;
        @Bind(R.id.tv_itemacountnumber)
        TextView tvItemacountnumber;

        ViewHolder(View view) {
            super(view);
            ButterKnife.bind(this, view);

//            itemView.setOnClickListener(new View.OnClickListener() {
//                @Override
//                public void onClick(View view) {
//                    Intent intent = new Intent();
//                    intent.putExtra("idname",id_item.getId_name());
//                    intent.putExtra("acountnumberlogo",id_item.getAcountnumberlogo());
//                    intent.setClass(loginId,IdItem.class);
//                    loginId.startActivity(intent);
//                }
//            });
        }
    }
}
